package com.hualan.controller;

import com.hualan.pojo.ArticleCategory;
import com.hualan.pojo.PageResult;
import com.hualan.pojo.Result;
import com.hualan.service.ArticleCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articleCategory")
public class ArticleCategoryController {
    @Autowired
    private ArticleCategoryService articleCategoryService;


    @GetMapping("/search")
    public Result queryAllArticleCategory(String categoryName,@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize){
        PageResult pageResult = articleCategoryService.queryAllArticleCategory(categoryName, page, pageSize);
        return Result.success(pageResult);
    }

    @PostMapping("/add")
    public Result addArticleCategory(@RequestBody ArticleCategory articleCategory){
        return articleCategoryService.addArticleCategory(articleCategory);
    }

    @PutMapping("/update")
    public Result updateArticleCategory(@RequestBody ArticleCategory articleCategory){
        return articleCategoryService.updateArticleCategory(articleCategory);
    }

    @PutMapping("/delete")
    public Result deleteArticleCategory(@RequestBody List<Integer> ids){
        return articleCategoryService.deleteArticleCategory(ids);
    }
}
